<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>管理员添加老师评价</title>
    <link rel="stylesheet" href="https://www.layuicdn.com/layui/css/layui.css">
</head>
<body>


<table id="demo" lay-filter="test"></table>


<script src="https://www.layuicdn.com/layui/layui.js"></script>
<script>
    layui.use(['table', 'layer','jquery'], function () {
        var table = layui.table;
        var layer = layui.layer;
        let $ = layui.jquery;

        table.render({
            elem: '#demo',
            height: 'auto',
            url: '/teacher/getTeachers', //数据接口,
            page: true, //开启分页
            toolbar: '#toolbarDemo', //开启头部工具栏，并为其绑定左侧模板
            cols: [[ //表
                {type: 'checkbox', fixed: 'left'},
                {field: 'teacherId', title: '工号', width: "20%"},
                {field: 'teacherName', title: '姓名', width: "20%"},
            ]],
            response: {
                statusCode: 200,//规定成功的状态码，默认：0
            },
            parseData: function(res){ //res 即为原始返回的数据
                return {
                    "code": res.code, //解析接口状态
                    "count": res.data.total, //解析数据长度
                    "data": res.data.list //解析数据列表
                };
            }
        });

        //头工具栏事件
        table.on('toolbar(test)', function(obj){
            var checkStatus = table.checkStatus(obj.config.id);
            switch(obj.event){
                case 'release':
                    var data = checkStatus.data;
                    $.ajax({
                        url: '/teacher/releaseEval',
                        type: 'post',
                        data:JSON.stringify(data),
                        contentType: "application/json; charset=utf-8",
                        success(response){
                            if (response.code==='200'){
                                layer.msg("发布成功");
                            }else{
                                layer.msg(response.msg);
                            }
                        }
                    })
                    break;
            };
        });

    })
</script>
<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm" lay-event="release">发布</button>
    </div>
</script>
</body>
</html>
